package configs

import (
	"github.com/spf13/cast"
	"lib/mall/v1/helpers"
	"os"
)

type Database struct {
	Host     string `form:"host"`
	Port     string `form:"port"`
	UserName string `form:"user_name"`
	Password string `form:"password"`
	Name     string `form:"database_name"`
}

func newDatabaseConfig() Database {
	return Database{
		Host:     cast.ToString(helpers.DefaultValue(os.Getenv("DATABASE_HOST"), "127.0.0.1")),
		Port:     cast.ToString(helpers.DefaultValue(os.Getenv("DATABASE_PORT"), 3306)),
		UserName: cast.ToString(helpers.DefaultValue(os.Getenv("DATABASE_USER_NAME"), "root")),
		Password: cast.ToString(helpers.DefaultValue(os.Getenv("DATABASE_PASSWORD"), "root")),
		Name:     cast.ToString(helpers.DefaultValue(os.Getenv("DATABASE_NAME"), "mall")),
	}
}
